﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
	/// <summary>
	/// 场景跳跃点配表脚本
	/// </summary>
	[ExecuteInEditMode]
	public class SceneJumppoint : SceneObject
	{
		public enum Ease
		{
			Unset = 0,
			Linear = 1,
			InSine = 2,
			OutSine = 3,
			InOutSine = 4,
			InQuad = 5,
			OutQuad = 6,
			InOutQuad = 7,
			InCubic = 8,
			OutCubic = 9,
			InOutCubic = 10,
			InQuart = 11,
			OutQuart = 12,
			InOutQuart = 13,
			InQuint = 14,
			OutQuint = 15,
			InOutQuint = 16,
			InExpo = 17,
			OutExpo = 18,
			InOutExpo = 19,
			InCirc = 20,
			OutCirc = 21,
			InOutCirc = 22,
			InElastic = 23,
			OutElastic = 24,
			InOutElastic = 25,
			InBack = 26,
			OutBack = 27,
			InOutBack = 28,
			InBounce = 29,
			OutBounce = 30,
			InOutBounce = 31,
			Flash = 32,
			InFlash = 33,
			OutFlash = 34,
			InOutFlash = 35,
		}

		[Serializable]
		public struct CG
		{
			/// <summary>
			/// 多个动画时执行顺序
			/// </summary>
			public int prof;
			/// <summary>
			/// CG资源
			/// </summary>
			[AssetType(typeof(CGController))]
			public AssetID cgController;
			/// <summary>
			/// 播放地点
			/// </summary>
			public Vector2 position;
			/// <summary>
			/// Y轴旋转
			/// </summary>
			public float rotationY;
		}

#if UNITY_EDITOR
		[SerializeField]
		[Header("当前跳跃点ID")]
		[Tooltip("当前跳跃点和目标跳跃点不能相互关联会形成死循环，必须在最后一个点上终结，设置一个不存在的跳跃点ID")]
		private int id;

		[SerializeField]
		[Header("目标跳跃点ID")]
		[Tooltip("当前跳跃点和目标跳跃点不能相互关联会形成死循环，必须在最后一个点上终结，设置一个不存在的跳跃点ID")]
		private int targetID;

		[Header("触发范围")]
		[Tooltip("不进行下一个跳点的设置为0")]
		[SerializeField]
		private int range;

		[Header("设置跳跃点上效果对象")]
		[Tooltip("如果不显示跳跃点效果使用0填写")]
		[SerializeField]
		private string resID = "tiaoyuedian";

		[Header("跳跃方式")]
		[Tooltip("角色有多个跳跃动画，1-10？，根据角色跳跃动作来旋转短距离和长距离的动作")]
		[SerializeField]
		private int jumpStyle = 1;


		[SerializeField]
		private float jumpSpeed = 1;

		[SerializeField]
		private Ease jumpEase = Ease.OutCubic;

		[Header("跳跃时是否播放CG")]
		[SerializeField]
		private bool playCG = false;

		[Header("播放的CG动画")]
		[Tooltip("如果有多个动画，后面必须连续配置多个对应的连续跳点，后面的每个跳点不能有动画配置。最好一个配置一个CG动画。")]
		[SerializeField]
		private CG[] cgs;


		public int ID
		{
			get { return this.id; }
		}

		public int TargetID
		{
			get { return this.targetID; }
		}

		public int Range
		{
			get { return this.range; }
		}

		public string ResID
		{
			get { return this.resID; }
		}

		public int JumpStyle
		{
			get { return this.jumpStyle; }
		}

		public float JumpSpeed
		{
			get { return this.jumpSpeed; }
		}

		public Ease JumpEase
		{
			get { return this.jumpEase; }
		}

		public bool PlayCG
		{
			get { return this.playCG; }
		}

		public CG[] CGs
		{
			get { return this.cgs; }
		}


		void OnValidate()
		{
			if (Application.isPlaying) return;

			// Setup name.
			this.name = "Jumppoint" + this.id.ToString();
		}
		void OnDrawGizmosSelected()
		{
			Gizmos.DrawWireSphere(transform.position, Mathf.Sqrt(range));
		}


#endif

	}
}

